home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / ClassAct / Examples / Bevel / bevelexample.c
C/C++ Source or Header  |  1997-08-05  |  4KB  |  203 lines

  1. ;/* Integer Example
  2. sc link bevelexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /**
  7.  **  BevelExample.c -- Bevel class Example.
  8.  **
  9.  **  This is a simple example testing some of the capabilities of the
  10.  **  Bevel gadget class.
  11.  **
  12.  **  This code opens a window and then creates 2 Bevel gadgets which
  13.  **  are subsequently attached to the window's gadget list.  One uses
  14.  **  arrows, one does not.  Notice that you can tab cycle between them.
  15.  **/
  16.  
  17. /* system includes
  18.  */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include <exec/types.h>
  24. #include <exec/memory.h>
  25. #include <intuition/intuition.h>
  26. #include <intuition/gadgetclass.h>
  27. #include <graphics/gfxbase.h>
  28. #include <graphics/text.h>
  29. #include <graphics/gfxmacros.h>
  30. #include <utility/tagitem.h>
  31. #include <workbench/startup.h>
  32. #include <workbench/workbench.h>
  33.  
  34. #include <proto/intuition.h>
  35. #include <proto/graphics.h>
  36. #include <proto/exec.h>
  37. #include <proto/dos.h>
  38. #include <proto/utility.h>
  39. #include <proto/wb.h>
  40. #include <proto/icon.h>
  41.  
  42. /* ClassAct includes
  43.  */
  44. #include <classact.h>
  45.  
  46.  
  47. enum
  48. {
  49.     GID_MAIN=0,
  50.     GID_QUIT,
  51.     GID_LAST
  52. };
  53.  
  54. enum
  55. {
  56.     WID_MAIN=0,
  57.     WID_LAST
  58. };
  59.  
  60. enum
  61. {
  62.     OID_MAIN=0,
  63.     OID_LAST
  64. };
  65.  
  66. int main(void)
  67. {
  68.     struct MsgPort *AppPort;
  69.  
  70.     struct Window *windows[WID_LAST];
  71.  
  72.     struct Gadget *gadgets[GID_LAST];
  73.  
  74.     Object *objects[OID_LAST];
  75.  
  76.     /* make sure our classes opened... */
  77.     if (!ButtonBase || !BevelBase || !WindowBase || !LayoutBase)
  78.         return(30);
  79.     else if ( AppPort = CreateMsgPort() )
  80.     {
  81.         /* Create the window object.
  82.          */
  83.         objects[OID_MAIN] = WindowObject,
  84.             WA_ScreenTitle, "ClassAct Release 2.0",
  85.             WA_Title, "ClassAct Bevel Example",
  86.             WA_Activate, TRUE,
  87.             WA_DepthGadget, TRUE,
  88.             WA_DragBar, TRUE,
  89.             WA_CloseGadget, TRUE,
  90.             WA_SizeGadget, TRUE,
  91.             WINDOW_IconifyGadget, TRUE,
  92.             WINDOW_IconTitle, "Bevel",
  93.             WINDOW_AppPort, AppPort,
  94.             WINDOW_Position, WPOS_CENTERMOUSE,
  95.             WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  96.                 LAYOUT_SpaceOuter, TRUE,
  97.                 LAYOUT_DeferLayout, TRUE,
  98.  
  99.                 LAYOUT_AddImage, BevelObject,
  100.                     BEVEL_FillPen, 0,
  101.                 BevelEnd,
  102.                 CHILD_MinWidth, 40,
  103.                 CHILD_MinHeight, 30,
  104.  
  105.                 LAYOUT_AddImage, BevelObject,
  106.                     BEVEL_Style, BVS_SBAR_VERT,
  107.                 BevelEnd,
  108.                 CHILD_MinWidth, 40,
  109.                 CHILD_MinHeight, 4,
  110.                 CHILD_WeightedHeight, 0,
  111.  
  112.                 LAYOUT_AddChild, ButtonObject,
  113.                     GA_ID, GID_QUIT,
  114.                     GA_RelVerify, TRUE,
  115.                     GA_Text,"_Quit",
  116.                 ButtonEnd,
  117.                 CHILD_WeightedHeight, 0,
  118.  
  119.             EndGroup,
  120.         EndWindow;
  121.  
  122.          /*  Object creation sucessful?
  123.           */
  124.         if (objects[OID_MAIN])
  125.         {
  126.             /*  Open the window.
  127.              */
  128.             if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  129.             {
  130.                 ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  131.                 ULONG done = FALSE;
  132.                 ULONG result;
  133.                 UWORD code;
  134.  
  135.                  /* Obtain the window wait signal mask.
  136.                  */
  137.                 GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  138.  
  139.                 /* Input Event Loop
  140.                  */
  141.                 while (!done)
  142.                 {
  143.                     wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  144.  
  145.                     if ( wait & SIGBREAKF_CTRL_C )
  146.                     {
  147.                         done = TRUE;
  148.                     }
  149.                     else
  150.                     {
  151.                         while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  152.                         {
  153.                             switch (result & WMHI_CLASSMASK)
  154.                             {
  155.                                 case WMHI_CLOSEWINDOW:
  156.                                     windows[WID_MAIN] = NULL;
  157.                                     done = TRUE;
  158.                                     break;
  159.  
  160.                                 case WMHI_GADGETUP:
  161.                                     switch (result & WMHI_GADGETMASK)
  162.                                     {
  163.                                         case GID_QUIT:
  164.                                             done = TRUE;
  165.                                             break;
  166.                                     }
  167.                                     break;
  168.  
  169.                                 case WMHI_ICONIFY:
  170.                                     CA_Iconify(objects[OID_MAIN]);
  171.                                     windows[WID_MAIN] = NULL;
  172.                                     break;
  173.  
  174.                                 case WMHI_UNICONIFY:
  175.                                     windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  176.  
  177.                                     if (windows[WID_MAIN])
  178.                                     {
  179.                                         GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  180.                                     }
  181.                                     else
  182.                                     {
  183.                                         done = TRUE;    // error re-opening window!
  184.                                     }
  185.                                      break;
  186.                             }
  187.                         }
  188.                     }
  189.                 }
  190.             }
  191.  
  192.             /* Disposing of the window object will also close the window if it is
  193.              * already opened, and it will dispose of the layout object attached to it.
  194.              */
  195.             DisposeObject(objects[OID_MAIN]);
  196.         }
  197.  
  198.         DeleteMsgPort(AppPort);
  199.     }
  200.  
  201.     return(0);
  202. }
  203.